package com.gp.study.mybatis.handler;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

public class ParameterHandler {

	public void handStatementParams(PreparedStatement prepareStatement, Object[] parameter) throws SQLException {
		Object temp = null;
		for(int i=0;i<parameter.length;i++){
			int k = i+1;  // 参数从1开始
			temp = parameter[i];
			if(temp instanceof Integer){
				prepareStatement.setInt(k,(int) temp);
			}else if(temp instanceof Long){
				prepareStatement.setLong(k, (long) temp);
			}else if(temp instanceof String){
				prepareStatement.setString(k, temp.toString());
			}else if(temp instanceof Boolean){
				prepareStatement.setBoolean(k, (boolean) temp);
			}else if(temp instanceof Date){
				prepareStatement.setDate(k, (java.sql.Date) temp);
			}else if(temp instanceof Timestamp){
				prepareStatement.setTimestamp(k, (java.sql.Timestamp) temp);
			}else{
				throw new RuntimeException("no support  parm type");
			}
		}
	}

}
